package org.tom.pay.controller;

import org.assertj.core.internal.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tom.basic.exception.MyException;
import org.tom.basic.util.JsonResult;
import org.tom.pay.dto.AlipayNotifyDto;
import org.tom.pay.service.IPayService;

@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private IPayService payService;

    @PostMapping("/applyPay/{sn}")
    public JsonResult toPay(@PathVariable("sn") String sn) { // 只能进行地址栏的方式接收不然接收的id后面会拼接一个#
        try {
            String htmlResult = payService.toPay(sn);
            System.out.println(htmlResult);
            return JsonResult.me().setResultObj(htmlResult);
        }catch (MyException e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("后端系统异常");
        }

    }

    @RequestMapping("/notify")
    public String alipayNotify(AlipayNotifyDto alipayNotifyDto){
        return payService.alipayNotify(alipayNotifyDto);
    }
}
